package gui;

import gui.menus.MenuBar;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;


import resources.GlobalSettings;
import resources.ImageBundle;
import controller.LevelFileController;
import controller.SokobanController;

public class MainWindow extends JFrame {

	private static final long serialVersionUID = 2740437090361841747L;

	public MainWindow() {
		super(GlobalSettings.appName);

		this.setIconImage(ImageBundle.get("app-icon_128"));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(new Dimension(GlobalSettings.mainWindowW,
				GlobalSettings.mainWindowH));

		LevelFileController levelFile = new LevelFileController();

		SokobanController sokoPanel = new SokobanController();
		// Agregar listener para escuchar EndLevel desde LevelFile
		sokoPanel.addEndLevelEventListener(levelFile);
		// Agregar listener para escuchar evento LevelFile cambiado desde sokoPanel 
		levelFile.addLevelFilePropertyChangeListener(sokoPanel);
		// Iniciar el nivel actual
		levelFile.actionRestartLevel();

		this.getContentPane().add(sokoPanel, BorderLayout.CENTER);

		// getLevelMemento no funciona si se cambia de nivel
		MenuBar menuBar = new MenuBar(levelFile, sokoPanel.getLevelMemento());
		this.setJMenuBar(menuBar);

		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}

}
